<?php
/**
 * Created by PhpStorm.
 * User: Guangpeng Chen
 * Date: 15-4-19
 * Time: 下午4:17
 */
define('IN_PFT', true);
include '../../class/Api.class.php';

if (empty($_SESSION['sid'])) {
    Api::Response('No permission', Api::authErrorCode);
}


include '../../common/func.inc.php';
include '../../class/Terminal.class.php';
include '../../class/SoapInit.class.php';
include '../../class/AccessRecord.php';

include '../common/Db.class.php';
$conf = include '../common/db.conf.php';
\PFT\Db::Conf($conf['localhost']);
$pdo = \PFT\Db::Connect();

$terminal = new \PFT\Terminal($pdo, SoapInit::GetSoapInside(), $_SESSION['sid'], $_POST['id']);

$action = trim($_POST['action']);
//print_r($_POST);
//exit;
switch($action) {
    case 'GLOBAL_CONFIG':
        $res = $terminal->GlobalTerminalChange(intval($_POST['terminal']), $_SESSION['sid']);
        if ($res===true) {
            echo '{"status":"ok"}';
        } else {
            echo '{"status":"fail"}';
        }
        break;
    case 'LAND_CONFIG':
        if (empty($_POST['id']) || !is_numeric($_POST['id'])) {
            Api::Response('Empty land id', Api::badRequestCode);
        }
        if ( $terminal->TerminalChange($_POST['terminal']) === true ) {
            echo '{"status":"ok"}';
        } else {
            echo '{"status":"fail"}';
        }
        break;
}